package com.engineering.elink.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.ws.rs.DefaultValue;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.engineering.elink.co.EnginHierCo;
import com.engineering.elink.service.EnginHomeService;

/**
 * 我的工程界首页restful接口
 */
@RestController
@CrossOrigin
@RequestMapping("/api/enginhome")
@Api(value="我的工程界首页接口")
public class EnginHomeController {

	@Autowired
	private EnginHomeService enginHomeService;
	
	/**
	 * 获取专属频道
	 */
	@RequestMapping(value = "/getExclusive", method = RequestMethod.GET)
	@ApiOperation(value = "获取专属频道")
	public Map<String, Object> getExclusive() {
		return enginHomeService.getExcluAll();
	}
	
	/**
	 * 获取职业规划
	 */
	@RequestMapping(value="/getProfePlann",method = RequestMethod.GET)
	@ApiOperation(value = "获取职业规划")
	public Map<String, Object> getProfePlann(@ModelAttribute @Valid EnginHierCo co){
		
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
//		String userId =  userInfo.get("userId").toString();
		
		return enginHomeService.getProfePlann(co,"");
	}
	
	/**
	 * 获取工程资料库
	 */
	@RequestMapping(value="/getEnginFile",method = RequestMethod.GET)
	@ApiOperation(value = "获取工程资料库")
	public Map<String, Object> getEnginFile(@ApiParam(value="二级类目ID",required=false) @RequestParam(value="scId",required=false) Integer scId,
			@ApiParam(value="三级类目ID",required=true) @RequestParam("dcId") int dcId,
			@ApiParam(value="左边右边显示条数,默认为4条",defaultValue="4") @RequestParam("count")@DefaultValue("4") int count){
		
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
//		String userId =  userInfo.get("userId").toString();
		
		return enginHomeService.getEnginFile(scId,dcId,"",count);
	}
	
	/**
	 * 获取培训视频
	 */
	@RequestMapping(value="/getEnginCourse",method = RequestMethod.GET)
	@ApiOperation(value = "获取培训视频")
	public Map<String, Object> getEnginCourse(@ApiParam(value="二级类目ID",required=false) @RequestParam(value="scId",required=false) Integer scId,
			@ApiParam(value="三级类目ID",required=true) @RequestParam("dcId") int dcId,
			@ApiParam(value="显示条数,默认为6条",defaultValue="6") @RequestParam("count")@DefaultValue("6") int count){
		
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
//		String userId =  userInfo.get("userId").toString();
		
		return enginHomeService.getEnginCourse(scId,dcId,"",count);
	}
	
	/**
	 * 获取论文图书馆
	 */
	@RequestMapping(value="/getEnginLibrary",method = RequestMethod.GET)
	@ApiOperation(value = "获取论文图书馆")
	public Map<String, Object> getEnginLibrary(@ApiParam(value="二级类目ID",required=false) @RequestParam(value="scId",required=false) Integer scId,
			@ApiParam(value="三级类目ID",required=true) @RequestParam("dcId") int dcId,
			@ApiParam(value="显示条数,默认为8条",defaultValue="8") @RequestParam("count")@DefaultValue("8") int count ){
		
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
//		String userId =  userInfo.get("userId").toString();
		
		return enginHomeService.getEnginLibrary(scId,dcId,"",count);
	}
	
	/**
	 * 获取百问百答
	 */
	@RequestMapping(value="/getEnginPostBar",method = RequestMethod.GET)
	@ApiOperation(value = "获取百问百答")
	public Map<String, Object> getEnginPostBar(@ApiParam(value="二级类目ID",required=false) @RequestParam(value="scId",required=false) Integer scId,
			@ApiParam(value="三级类目ID",required=true) @RequestParam("dcId") int dcId,
			@ApiParam(value="职业体系ID",required=true) @RequestParam("hierId") int hierId,
			@ApiParam(value="显示条数,默认为3条",defaultValue="3") @RequestParam("count")@DefaultValue("3") int count ){
		
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
//		String userId =  userInfo.get("userId").toString();
		
		return enginHomeService.getEnginPostBar(scId,dcId,hierId,count,"");
	}
	
	/**
	 * 获取新闻资迅
	 */
	@RequestMapping(value="/getEnginNews",method = RequestMethod.GET)
	@ApiOperation(value = "获取新闻资迅")
	public Map<String, Object> getEnginNews(){
		
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
//		String userId =  userInfo.get("userId").toString();
		
		return enginHomeService.getEnginNews("");
	}
	
	@RequestMapping(value="/getEnginBrowse",method = RequestMethod.GET)
	@ApiOperation(value = "获取浏览记录")
	public Map<String, Object> getEnginBrowse(
			@ApiParam(value="显示条数,默认为6条",defaultValue="6") @RequestParam("count")@DefaultValue("6") int count,HttpServletRequest request){
		
		@SuppressWarnings("unchecked")
		Map<String,Object> userInfo  = (Map<String, Object>) request.getAttribute("userInfo");
		String userId =  userInfo.get("userId").toString();
		
		return enginHomeService.getEnginBrowse(userId,count);
	}
	
}
